﻿<%@ Page Language="C#" Inherits="System.Web.Mvc.ViewPage<dynamic>" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title>Direct Web App Server</title>
    <% Html.RenderPartial("PageIncludes"); %>
    <style type="text/css">
        #logon-body { }
        #logon-body-content { position: absolute; top: 0; left: 0; right: 0; bottom: 0; }
        #server-info { padding: 20px; background: transparent url(/core/theme/shell/logo_big.png) no-repeat left center; float: left; margin-left: 15px; padding-left: 65px; }
        #server-name { font-size: .9em; }
        #version { display: block; font-size: .8em; opacity: .8; }
        #company-name { margin-top: 4px; font-size: 1.5em; }
        #logon-box { position: absolute; top: 50%; left: 50%; font-size: 13px; margin-top: -100px; margin-left: -125px; }
        #logon-box .ui-widget-header { padding: 10px; }
        #logon-box label { display: block; margin-top: 10px; }
        #logon-box input { width: 250px; padding: 6px; }
        #logon-box-content { padding: 35px; }
        #logon-buttons { text-align: right; padding-top: 15px; }
        #comercial-info { position: absolute; bottom: 0; right: 0; padding: 5px; font-size: 11px; text-align: center; left: 0; }
        #spinner { display: inline-block; background: transparent url(/core/theme/shell/spinner.gif) no-repeat left center; text-indent: 19px; float: left; margin-top: 10px; }
    </style>
    <script type="text/javascript">
        $(function ()
        {
            $("#logon-button").button();
            setTimeout(function () { $("#user").focus(); }, 50);

            var spinner = $("#spinner");
            spinner.hide();

            $("#logon-button").click(function (e)
            {
                var _this = $(this);
                var user = $("#user").val().trim();
                var pwd = $("#pwd").val().trim();
                if (!user.length)
                {
                    alert("Informe seu nome de usuário.");
                    $("#user").focus();
                    return;
                }
                if (!pwd.length)
                {
                    alert("Informe sua senha.");
                    $("#pwd").focus();
                    return;
                }
                e.preventDefault();
                e.stopPropagation();

                _this.css("visibility", "hidden");
                spinner.show();

                $.ajax({
                    url: '/Auth/Logon',
                    data: { u: user, p: pwd, n: '/r' },
                    success: function (result)
                    {
                        if (!result)
                        {
                            spinner.hide();
                            alert("Oops! ocorreu um problema na comunicação com o servidor.");
                            _this.css("visibility", "visible");
                        }
                        else if (result.loggedOn)
                            window.location = result.next;
                        else
                        {
                            spinner.hide();
                            alert(result.msg);
                            _this.css("visibility", "visible");
                            $("#user").focus().select();
                            return;
                        }
                    },
                    error: function ()
                    {
                        spinner.hide();
                        alert(result.msg);
                        _this.css("visibility", "visible");
                    }
                });
            });

            $("body").ajaxError(function ()
            {
                alert("Oops! ocorreu um problema na comunicação com o servidor.");
                spinner.hide();
                $("#logon-button").css("visibility", "visible");
            });

        });
    </script>
</head>
<body>
    <%
        var productInfo = ServiceLocator.GetInstance<Direct.Product.IProductService>();
        var license = productInfo.GetLicenseInformation();
    %>
    <div id="logon-body" class="shell-content">
        <div id="logon-body-content" class="ui-widget ui-widget-content">
            <div id="server-info">
                <div id="company-name">
                    <%= license.CompanyComercialName %>
                </div>
                <div id="server-name">
                    <%= productInfo.ProductName %>
                    <span id="version">
                        <%= productInfo.ProductVersion %></span>
                </div>
            </div>
            <div id="logon-box">
                <div class="ui-widget-header ui-corner-top">
                    Logon
                </div>
                <div id="logon-box-content" class="ui-widget-content ui-corner-bottom">
                    <form action="/" method="post">
                    <label for="user">
                        Login</label>
                    <input type="text" id="user" name="user" />
                    <label for="pwd">
                        Senha</label>
                    <input type="password" id="pwd" name="pwd" />
                    <br />
                    <a href="/Login/Forgot?fwd=referrer">Esqueceu sua senha?</a>
                    <div id="logon-buttons">
                        <span id="spinner">
                            Entrando...
                        </span>
                        <button id="logon-button">
                            Entrar</button>
                    </div>
                    </form>
                </div>
            </div>
            <div id="comercial-info">
                (c)2009-2011 Marcelo Dezem (<a href="mailto: mdezem@hotmail.com">mdezem@hotmail.com</a>). Todos os direitos reservados. Este aplicativo usa partes ou todo o código de bibliotecas <i>open source</i>, consulte a sessão <b>sobre</b> para mais informações.
            </div>
        </div>
    </div>
</body>
</html>
